package com.examp.dy.dy.controller;

import com.examp.dy.dy.dao.BookRepository;
import com.examp.dy.dy.dao.BorrowRepository;
import com.examp.dy.dy.entities.Book;
import com.examp.dy.dy.entities.Borrow;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class BorrowController  {
    @Autowired
    BorrowRepository borrowRepository;

    @RequestMapping("/borrow")
    public String Borrow(Model model){
        Borrow borrow = new Borrow();
        model.addAttribute("Borrow",borrow);
        return "/main/borrowing information";
    }
    @RequestMapping("/save1")
    public String BorrowSave(Model model,Borrow borrow){
       borrowRepository.save(borrow);
        return "redirect:/borrow";
    }
    @RequestMapping("/borrow2")
        public String BorrowTime(Model model){
        List<Borrow> borrows = borrowRepository.findAll();
        model.addAttribute("Borrows",borrows);
        return "/main/borrowing information";
    }



}
